﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ADC.Utilites;
using ADC.BL;

namespace ADC.Web.Admin
{
    public partial class ListRecruitment : System.Web.UI.Page
    {
        log4net.ILog logger = log4net.LogManager.GetLogger("ListRecruitment");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Page.Title = Common.PAGE_TITLE + "Danh muc tuyen dung";
                BindData();
            }
        }

        private void BindData()
        {
            try
            {
                var listRecruitment = RecruitmentFactory.ListAll();
                GridViewConsulting.AutoGenerateColumns = false;
                GridViewConsulting.DataSource = listRecruitment;
                GridViewConsulting.DataBind();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsEnableDebugMode) throw;
            }

        }

        protected void GridViewConsulting_RowEditing(object sender, GridViewEditEventArgs e)
        {
            try
            {
                var lblConsultingID = (Label)GridViewConsulting.Rows[e.NewEditIndex].FindControl("lblConsultingID");
                if (lblConsultingID != null && !string.IsNullOrEmpty(lblConsultingID.Text))
                {
                    Response.Redirect("ManageRecruitment.aspx?Mode=1&ID=" + lblConsultingID.Text, false);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsEnableDebugMode) throw;
            }
        }

        protected void GridViewConsulting_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                var lblConsultingID = (Label)GridViewConsulting.Rows[e.RowIndex].FindControl("lblConsultingID");
                if (lblConsultingID != null && !string.IsNullOrEmpty(lblConsultingID.Text))
                {
                    int result = RecruitmentFactory.Delete(Convert.ToInt32(lblConsultingID.Text));
                    BindData();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsEnableDebugMode) throw;
            }
        }
    }
}